//
//  URLConvertible.swift
//  live
//
//  Created by melvyn on 2018/9/24.
//  Copyright © 2018 NEET. All rights reserved.
//

import Foundation

enum ALError: Error {
    case invalidURL(String)
}

protocol URLConvertible {
    func asURL() throws -> URL
}

extension String: URLConvertible {
    func asURL() throws -> URL {
        guard let url = URL.init(string: self) else { throw ALError.invalidURL(self)  }
        
        return url
    }
}

extension URL: URLConvertible {
    func asURL() throws -> URL {
        return self
    }
}
